$(function(){
	
			listResourceFile();
			listArticle();
			$('#yc_intag ul li').click(function(){
					var index = $(this).index();
					$(this).addClass('yc-li').siblings().removeClass('yc-li');
					$('.yc_incont:eq('+index+')').css('display','block').siblings().css('display','none');
			});
			
			var showLi = $('#versionShow .show');
			$.each(showLi,function(index,value){
				if(index != 0){
					var $show = $(value);
					$show.siblings().hide();
				}
			});
			
			$('.show').click(function(){
					$(this).siblings().fadeToggle("slow");
					var expand = $(">span",this).eq(1).html();
					if(expand == '+' ){
						$(">span",this).eq(1).html('-');
					}else{
						$(">span",this).eq(1).html('+');
					}
			});
	});
			
		function listArticle(){
			//文章
			$.ajax({
				type:'POST',
				url:'listArticle',
				dataType:'json',
				success:function(data){
					if(data && data.success){
						$('#article').empty();
						for(var i=0;i<data.object.length;i++){
							if(data.object[i].articleTitle.length >36){
								var articleTitle = data.object[i].articleTitle.substring(1,36);
								$('#article').append("<p><a target=\"_blank\" href=\"expose/article/detail/"+data.object[i].id+"\">"+articleTitle+"...</a></p>");
							}else{
								$('#article').append("<p><a target=\"_blank\" href=\"expose/article/detail/"+data.object[i].id+"\">"+data.object[i].articleTitle+"</a></p>");
							}
						}
					}else{
						$('#article').append("<li>出错啦!</li>");
					}
				}
			});
		}
		
		function listResourceFile(){
			//最新下载
			$.ajax({
				type:'POST',
				url:'listResourceFile',
				dataType:'json',
				success:function(data){
					if(data && data.success){
							$('#rfile').empty();
						for(var i=0;i<data.object.length;i++){
							if(data.object[i].resourceTitle.length >30){
								var resourceTitle = data.object[i].resourceTitle.substring(1,30);
								$('#rfile').append("<li><a target=\"_blank\" href=\"expose/resource/detail?id="+data.object[i].id+"\">"+resourceTitle+"</a></li>");
							}else{
								$('#rfile').append("<li><a target=\"_blank\" href=\"expose/resource/detail?id="+data.object[i].id+"\">"+data.object[i].resourceTitle+"</a></li>");
							}
						}
					}else{
						$('#rfile').append("<li>出错啦!</li>");
					}
				}
			});
		}

		
setInterval("listArticle()",1000*60*30);
setInterval("listResourceFile()",1000*60*30);

/**
 * 动态赞
 */
function momentsThumbUp(id){
	$.ajax({
		type:'POST',
		url:'user/moments/momentsThumbUp',
		data:{"momentsId":id},
		dataType:'json',
		success:function(data){
					if(data && data.success){
						$('#thumbUpNum'+id).html(data.object.thumbUpNum);
					}else if(data.code == 102){
						showDiv(data.message);
					}else{
						showAlertDiv(data.message);
					}
		}
	});
}

/**
 * 动态评论
 */
function momentsComment(userId,id){
	$.ajax({
		type:'POST',
		url:'user/moments/momentsComment',
		data:{"userId":userId,"momentsId":id},
		dataType:'json',
		success:function(data){
			if(data && data.success){
				$('#commentNum'+id).html('评论('+data.object.commentNum+')');
			}else if(data.code == 102){
				showDiv(data.message);
			}else{
				showAlertDiv(data.message);
			}
		}
	});
}

/**
 * 联系我发送邮件
 */
function sendEmail(){
	var email = document.getElementById("email").value;
	var content = document.getElementById("content").value;
	if(email ==''){
		showAlertDiv('请留下你的邮箱!');
		return false;
	}
	if(content == ''){
		showAlertDiv('请留下你的意见!');
		return false;
	}
	$.post('sendEmail',{"email":email,"content":content},
			function(data){
				if(data && data.success){
					showAlertDiv('恭喜你，邮件发送成功!');
					document.getElementById("form-send").reset();
				}else{
					showAlertDiv('很遗憾，邮件发送失败!');
				}
			},'json'
		);
}

